package com.jiangxiaofei.citycloud.mvp;

import android.content.Context;
import android.widget.Toast;

import com.blankj.utilcode.util.EmptyUtils;
import com.jiangxiaofei.citycloud.bean.FleaGoodBean;
import com.jiangxiaofei.citycloud.bean.GoodDetailBean;
import com.jiangxiaofei.citycloud.bean.GoodListBean;
import com.jiangxiaofei.citycloud.bean.FleaMenuBean;
import com.jiangxiaofei.citycloud.httpUtil.OnLoadDataIm;
import com.jiangxiaofei.citycloud.param.FleaChildGoodsParam;
import com.jiangxiaofei.citycloud.param.FleaGetDetailParam;
import com.jiangxiaofei.citycloud.param.FleaGoodListParam;
import com.jiangxiaofei.citycloud.param.GoodsPublicParam;
import com.jiangxiaofei.citycloud.param.FleaNeedListParam;
import com.jiangxiaofei.citycloud.param.PutNeedParam;
import com.jiangxiaofei.citycloud.param.SearchParam;

import java.util.List;

/**
 * @author: JiangXFei
 * @date: 2017/11/9 0009
 * @content: 二手物资交流
 */

public class FleaPersenter implements FleaConstant.GetFleanMenuPersenter, FleaConstant.PutFleaGoodsPersenter
        , FleaConstant.GetNewGoodsPersenter, FleaConstant.GetGoodDetailPersenter,
        FleaConstant.GetChildNewGoodsPersenter, FleaConstant.GetGoodListPersenter,
        FleaConstant.PutNeedPersenter, FleaConstant.GetNeedDetailPersenter,
        FleaConstant.GetNeedListPersenter, FleaConstant.SearchGoodPersenter,
        FleaConstant.SearchNeedPersenter {
    Context mContext;
    FleaConstant.GetFleaMenuMobel getFleaMenuMobel;
    FleaConstant.GetFleaMenuView getFleaMenuView;

    public FleaPersenter(Context mContext, FleaConstant.GetFleaMenuView getFleaMenuView) {
        this.mContext = mContext;
        this.getFleaMenuView = getFleaMenuView;
        getFleaMenuMobel = new FleaModel();
    }

    FleaConstant.PutFleaGoodsModel putFleaGoodsModel;
    FleaConstant.PutFleaGoodsView putFleaGoodsView;

    public FleaPersenter(Context mContext, FleaConstant.PutFleaGoodsView putFleaGoodsView) {
        this.mContext = mContext;
        this.putFleaGoodsView = putFleaGoodsView;
        this.putFleaGoodsModel = new FleaModel();
    }

    FleaConstant.GetNewGoodsModel getNewGoodsModel;
    FleaConstant.GetNewGoodsView getNewGoodsView;

    public FleaPersenter(Context mContext, FleaConstant.GetNewGoodsView getNewGoodsView) {
        this.mContext = mContext;
        this.getNewGoodsView = getNewGoodsView;
        this.getNewGoodsModel = new FleaModel();
    }

    FleaConstant.GetGoodDetailModel getGoodDetailModel;
    FleaConstant.GetGoodDetailView getGoodDetailView;

    public FleaPersenter(Context mContext, FleaConstant.GetGoodDetailView getGoodDetailView) {
        this.mContext = mContext;
        this.getGoodDetailView = getGoodDetailView;
        this.getGoodDetailModel = new FleaModel();
    }

    FleaConstant.GetChildNewGoodsModel getChildNewGoodsModel;
    FleaConstant.GetChildNewGoodsView getChildNewGoodsView;

    public FleaPersenter(Context mContext, FleaConstant.GetChildNewGoodsView getChildNewGoodsView) {
        this.mContext = mContext;
        this.getChildNewGoodsView = getChildNewGoodsView;
        this.getChildNewGoodsModel = new FleaModel();
    }

    FleaConstant.GetGoodListModel getGoodListModel;
    FleaConstant.GetGoodListView getGoodListView;

    public FleaPersenter(Context mContext, FleaConstant.GetGoodListView getGoodListView) {
        this.mContext = mContext;
        this.getGoodListView = getGoodListView;
        this.getGoodListModel = new FleaModel();
    }

    FleaConstant.PutNeedModel putNeedModel;
    FleaConstant.PutNeedView putNeedView;

    public FleaPersenter(Context mContext, FleaConstant.PutNeedView putNeedView) {
        this.mContext = mContext;
        this.putNeedView = putNeedView;
        this.putNeedModel = new FleaModel();
    }

    FleaConstant.GetNeedDetailModel getNeedDetailModel;
    FleaConstant.GetNeedDetailView getNeedDetailView;

    public FleaPersenter(Context mContext, FleaConstant.GetNeedDetailView getNeedDetailView) {
        this.mContext = mContext;
        this.getNeedDetailView = getNeedDetailView;
        this.getNeedDetailModel = new FleaModel();
    }

    FleaConstant.GetNeedListModel getNeedListModel;
    FleaConstant.GetNeedListView getNeedListView;

    public FleaPersenter(Context mContext, FleaConstant.GetNeedListView getNeedListView) {
        this.mContext = mContext;
        this.getNeedListView = getNeedListView;
        this.getNeedListModel = new FleaModel();
    }

    FleaConstant.SearchGoodModel searchGoodModel;
    FleaConstant.SearchGoodView searchGoodView;

    public FleaPersenter(Context mContext, FleaConstant.SearchGoodView searchGoodView) {
        this.mContext = mContext;
        this.searchGoodView = searchGoodView;
        this.searchGoodModel = new FleaModel();
    }

    FleaConstant.SearchNeedModel searchNeedModel;
    FleaConstant.SearchNeedView searchNeedView;

    public FleaPersenter(Context mContext, FleaConstant.SearchNeedView searchNeedView) {
        this.mContext = mContext;
        this.searchNeedView = searchNeedView;
        this.searchNeedModel = new FleaModel();
    }

    /**
     * 二级菜单
     */
    @Override
    public void getFleaSencendMenu() {
        int id = getFleaMenuView.getFleaMenu();
        if (EmptyUtils.isNotEmpty(id) && !(id < 0)) {
            getFleaMenuMobel.getSencendMenu(mContext, id, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getFleaMenuView.getFleaSencendMenuOnSuccess((List<FleaMenuBean>) o);
                    } else {
                        toast("未找到分类");
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {
                    getFleaMenuView.getFleaSencendMenuOnSuccess(null);
                }
            });
        }
    }

    /**
     * 三级菜单
     */
    @Override
    public void getFleaThreeMenu() {
        int id = getFleaMenuView.getFleaMenu();
        if (EmptyUtils.isNotEmpty(id) && !(id < 0)) {
            getFleaMenuMobel.getThreeMenu(mContext, id, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getFleaMenuView.getFleaThreeMenuOnSuccess((List<FleaMenuBean>) o);
                    } else {
                        toast("未找到分类");
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                    getFleaMenuView.getFleaThreeMenuOnSuccess(null);
                }
            });
        }
    }

    /**
     * 获取主菜单
     */
    @Override
    public void getMainFleaMenu() {
        int id = getFleaMenuView.getFleaMenu();
        if (EmptyUtils.isNotEmpty(id) && !(id < 0)) {
            getFleaMenuMobel.getMainFleaMenu(mContext, id, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getFleaMenuView.getFleaMainMenuOnSuccess((List<FleaMenuBean>) o);
                    } else {
                        toast("未找到分类");
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                    getFleaMenuView.getFleaMainMenuOnSuccess(null);
                }
            });
        }
    }


    public void toast(String str) {
        Toast.makeText(mContext, str, Toast.LENGTH_SHORT).show();
    }

    /**
     * 发布二手商品
     */
    @Override
    public void putFleaGoods() {
        GoodsPublicParam fleaGoodsParam = putFleaGoodsView.getFleaGoodsParam();
        if (EmptyUtils.isNotEmpty(fleaGoodsParam)) {
            putFleaGoodsModel.putFleaGoods(mContext, fleaGoodsParam, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        putFleaGoodsView.onPutSuccesss(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    /**
     * 获取最新发布商品列表
     */
    @Override
    public void getNewGoods() {
        int newGoodsPage = getNewGoodsView.getNewGoodsPage();
        if (newGoodsPage > 0) {
            getNewGoodsModel.getNewGoods(mContext, newGoodsPage, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getNewGoodsView.getNewGoodsSuccess((List<FleaGoodBean>) o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    /**
     * 获取商品详情
     */
    @Override
    public void getGoodDetail() {
        FleaGetDetailParam goodDetailParam = getGoodDetailView.getGoodDetailParam();
        if (EmptyUtils.isNotEmpty(goodDetailParam)) {
            getGoodDetailModel.getGoodDetail(mContext, goodDetailParam, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getGoodDetailView.getGoodDetailOnSuccess((List<GoodDetailBean>) o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    /**
     * 获取二级页面商品列表
     */
    @Override
    public void getChildNewGoods() {
        FleaChildGoodsParam param = getChildNewGoodsView.getChildNewGoodsParam();
        if (EmptyUtils.isNotEmpty(param)) {
            getChildNewGoodsModel.getChildNewGoods(mContext, param, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getChildNewGoodsView.childNewGoodsOnSuccess((List<FleaGoodBean>) o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }


    /**
     * 获取商品筛选列表
     */
    @Override
    public void getGoodList() {
        FleaGoodListParam goodListParam = getGoodListView.getGoodListParam();
        if (EmptyUtils.isNotEmpty(goodListParam)) {
            getGoodListModel.getGoodList(mContext, goodListParam, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getGoodListView.goodListSuccess((List<GoodListBean>) o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    /**
     * 发布需求
     */
    @Override
    public void putNeed() {
        PutNeedParam param = putNeedView.getPutNeedParam();
        if (EmptyUtils.isNotEmpty(param)) {
            putNeedModel.putNeed(mContext, param, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        putNeedView.putNeedSuccess(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {
                }
            });
        }
    }

    /**
     * 获取需求详情
     */
    @Override
    public void getNeedDetail() {
        FleaGetDetailParam param = getNeedDetailView.getNeedDetailParam();
        if (EmptyUtils.isNotEmpty(param)) {
            getNeedDetailModel.getNeedDetail(mContext, param, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getNeedDetailView.needDetailOnSuccess(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    /**
     * 获取需求列表
     */
    @Override
    public void getNeedList() {
        FleaNeedListParam param = getNeedListView.getNeedListParam();
        if (EmptyUtils.isNotEmpty(param)) {
            getNeedListModel.getNeedList(mContext, param, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        getNeedListView.getNeedListOnSuccess(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    /**
     * 商品搜索
     */
    @Override
    public void searchGood() {
        SearchParam param = searchGoodView.getSearchGoodsParam();
        if (EmptyUtils.isNotEmpty(param)) {
            searchGoodModel.searchGood(mContext, param, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        searchGoodView.searchGoodSuccess(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }

    /**
     * 需求搜索
     */
    @Override
    public void searchNeed() {
        SearchParam param = searchNeedView.getSearchNeedParam();
        if (EmptyUtils.isNotEmpty(param)) {
            searchNeedModel.searchNeed(mContext, param, new OnLoadDataIm() {
                @Override
                public void onSuccess(Object o, int resultCode) {

                }

                @Override
                public void onSuccess(Object o, String message, int resultCode) {
                    if (EmptyUtils.isNotEmpty(o)) {
                        searchNeedView.searchNeedSuccess(o);
                    }
                }

                @Override
                public void onFailure(String msg, int resultCode) {

                }
            });
        }
    }
}
